﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UserGUI : MonoBehaviour {
    GUIStyle styleReady;
    IUserAction userac;

    void Awake() {
        styleReady = new GUIStyle();
        styleReady.fontSize = 30;
    }
    void Start() {
        userac = Singleton<GameController>.Instance as IUserAction;
        if (userac == null) {
            Debug.LogError("action is null");
        }
    }
    void Update() {
        /* 检测鼠标点击飞碟 */
        if (userac.GetGameState() != GameState.INGAME) {
            return;
        }
        if (Input.GetMouseButtonUp(0)) {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit)) {
                userac.HitDisk(hit.transform.gameObject);
            }
        }

    }
    void OnGUI() {
        /* 显示左上角分数 */
        if (userac.GetGameState() != GameState.OVER) {
            GUI.Label(new Rect(0, 0, 200, 50), "SCORE: " + userac.GetScore());
        }

        /* 准备状态下显示提示语 */
        if (userac.GetGameState() == GameState.READY) {
            float width = 300;
            float height = 100;
            GUI.Label(new Rect((Screen.width - width) * 0.5f, (Screen.height - height) * 0.5f, width, height), "ROUND " + userac.GetRound(), styleReady);
        }

        /* 游戏结束 */
        if (userac.GetGameState() == GameState.OVER) {
            float width = 300;
            float height = 100;
            GUI.Label(new Rect((Screen.width - width) * 0.5f, (Screen.height - height) * 0.5f, width, height), "FINAL SCORE: " + userac.GetScore(), styleReady);
            if (GUI.Button(new Rect((Screen.width - width) * 0.5f, (Screen.height - height) * 0.5f + 100.0f, width, height), "RESTART")) {
                userac.Init();
            }
        }
    }
}
